package xhe.lib.net;

import javax.servlet.http.HttpServletRequest;

public class Client {

	/**
	 *
	 * @request HttpServletRequest 客户端请求参数
	 * @return String IP地址
	 * @description: 获取客户端请求IP地址
	 * @author: xhe
	 * @date: 2024-07-11
	 * @version: V1.0
	 */
	public static String getIP(HttpServletRequest request) {
		String clientIp = request.getHeader("X-Forwarded-For");
		if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
			clientIp = request.getHeader("Proxy-Client-IP");
		}
		if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
			clientIp = request.getHeader("WL-Proxy-Client-IP");
		}
		if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
			clientIp = request.getRemoteAddr();
		}
		return clientIp;
	}
}
